package com.sa.token.controller;

import com.sa.token.dto.request.menu.InsertMenuRequest;
import com.sa.token.dto.request.menu.SelectMenuByIdRequest;
import com.sa.token.dto.request.menu.SelectMenuRequest;
import com.sa.token.message.StandardResponse;
import com.sa.token.service.SysMenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @desc： 菜单的基本接口
 * @author： xhs
 * @date： 2021/9/14 14:56
 * @version： JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/api/menu")
public class MenuController {

    @Autowired
    private SysMenuService menuService;

    /**
     * 新增菜单接口
     *
     * @param request
     * @param menuRequest
     * @return
     */
    @PostMapping("/insertMenu")
    public StandardResponse insertMenu(HttpServletRequest request, @Valid @RequestBody InsertMenuRequest menuRequest) {
        log.info("-----------------【新增菜单接口入参 menuJson：{}】--------------", menuRequest.toString());
        StandardResponse response = menuService.insertMenu(request, menuRequest);
        return response;
    }

    /**
     * 查询菜单接口
     *
     * @param menuRequest
     * @return
     */
    @PostMapping("/selectMenu")
    public StandardResponse selectMenu(@Valid @RequestBody SelectMenuRequest menuRequest) {
        log.info("-----------------【查询菜单接口入参 menuRequest：{}】--------------", menuRequest.toString());
        StandardResponse menu = menuService.selectMenu(menuRequest);
        return menu;
    }

    /**
     * 根据Id查询菜单
     *
     * @param menuRequest
     * @return
     */
    @PostMapping("/selectMenuById")
    public StandardResponse selectMenuById(@Valid @RequestBody SelectMenuByIdRequest menuRequest) {
        log.info("-----------------【查询菜单接口入参 menuRequest：{}】--------------", menuRequest.toString());
        StandardResponse menu = menuService.selectMenuById(menuRequest);
        return menu;
    }
}
